﻿@namespace Aspire.Dashboard.Components
@using System.Globalization
@using Aspire.Dashboard.Model
@using Aspire.Dashboard.Utils
@using Aspire.Hosting.ConsoleLogs
@inject IJSRuntime JS
@implements IAsyncDisposable

<div class="log-overflow console-overflow continuous-scroll-overflow">
    <div class="log-container console-container" id="logContainer">
        <Virtualize Items="@LogEntries.GetEntries()" ItemSize="20" OverscanCount="100" TItem="LogEntry">
            <div class="log-line-row-container">
                <div class="log-line-row console-line-row">
                    <span class="log-line-area" role="log">
                        <span class="log-line-number">@context.LineNumber</span>
                        <span class="log-content">
                            @{
                                var hasPrefix = false;
                            }
                            @if (context.Timestamp is { } timestamp)
                            {
                                hasPrefix = true;
                                <span class="timestamp" title="@FormatHelpers.FormatDateTime(TimeProvider, timestamp, MillisecondsDisplay.Full, CultureInfo.CurrentCulture)">@GetDisplayTimestamp(timestamp)</span>
                            }
                            @if (context.Type == LogEntryType.Error)
                            {
                                hasPrefix = true;
                                <fluent-badge appearance="accent">stderr</fluent-badge>
                            }
                            @((MarkupString)((hasPrefix ? "&#32;" : string.Empty) + (context.Content ?? string.Empty)))
                        </span>
                    </span>
                </div>
            </div>
        </Virtualize>
    </div>
</div>
